package org.tc.feign.client.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.tc.client.entity.Comments;
import org.tc.feign.client.service.FeignCommentsService;

import java.util.List;

@CrossOrigin(origins = {"*"},methods={RequestMethod.GET,RequestMethod.POST,RequestMethod.OPTIONS})
@RestController
public class FeignCommentsController {

    @Autowired
    private FeignCommentsService feignCommentsService;

    @RequestMapping("/selectCommentsByComId")
    @ResponseBody
    public List<Comments>  selectCommentsByComId(@RequestParam(value = "commodityid") Integer commodityId){
        System.out.println("商品"+commodityId+"的评论");
        return  feignCommentsService.selectCommentsByComId(commodityId);
    }

    @RequestMapping("/selectCommentsByGood")
    @ResponseBody
    public List<Comments>  selectCommentsByGood(@RequestParam(value = "commodityid",required = false) Integer commodityId){
        System.out.println("商品"+commodityId+"的好评论");
        return  feignCommentsService.selectCommentsByGood(commodityId);
    }

    @RequestMapping("/selectCommentsByMiddle")
    @ResponseBody
    public List<Comments>  selectCommentsByMiddle(@RequestParam(value = "commodityid",required = false) Integer commodityId){
        System.out.println("商品"+commodityId+"的中评论");
        return  feignCommentsService.selectCommentsByMiddle(commodityId);
    }

    @RequestMapping("/selectCommentsByBad")
    @ResponseBody
    public List<Comments>  selectCommentsByBad(@RequestParam(value = "commodityid",required = false) Integer commodityId){
        System.out.println("商品"+commodityId+"的差评论");
        return  feignCommentsService.selectCommentsByBad(commodityId);
    }
    @RequestMapping("/insertComments")
    @ResponseBody
    public int insertComments(@RequestBody Comments comments){
        System.out.println(comments.getNickname()+"发表评论");
        return feignCommentsService.insertComments(comments);

    }
}
